<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form id="form2" name="form2">
	<input type="hidden" name="userid" id="userid" value="${user.id}">
	<input type="hidden" name="dutyids" id="dutyids">
</form>
<form name="form1" id="form1" action="<%-- ${systemctx}/sample/saveSample.web --%>" method="post">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.bascsetting.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.manage.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.manage.list.title") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.dutyname") %>
						</label>
						<span><input type="text" class="input-sm" id="dutyname" name="dutyname" value="" /></span> 
					</li>
				</ul>
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" name="butQuery" value="<%=MessageResourcesUtils.getMessage(request, "common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="add()" value="<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.button.name") %>" />
			<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back")%>' />
		</div>
		<table >
			<tbody>
				<tr>
					<td>
						<table class="easyui-datagrid" id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>
<script type="text/javascript">
	function add(){
		var rows = $('#datagrid').datagrid('getSelections');
		if(rows.length == 0){
			alert('<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.choose.alert.title")%>');
			return;
		}else{
			var ids = '';
			for(var i=0; i<rows.length; i++){
				ids=ids+rows[i].dutyid+",";
			}
			$("#dutyids").val(ids);
		}
		
		if(confirm('<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.message.confirm.info")%>')){
			// 显示进度条
			showSending();
			$.ajax({
				type : 'POST',
				url : '${systemctx}/systemmanage/userDuty/user/insert.web',
				data : $("#form2").serialize(),
				dataType : 'json',
				success : function(data) {
					//关闭执行...
					closeSending();
					//显示AJAX请求后的提示信息
					if(data.result == 'success'){
						alert('<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.alert.message.success")%>');
						window.location.href = "${systemctx}/systemmanage/userDuty/user/list.web";
					}else {
						alert('<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.alert.message.error")%>');
						return;
					}
				}
			});
		}
	}

	$(document).ready(function() {
		$('#butReturn').click(function() {
			parent.document.location.reload();
			$.fn.closeIssWindow();
		});
		var ids = '${idList}';
		//加载分页控件 datagrid
		$('#datagrid').datagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.list") %>',
			width : 1110,
			nowrap : true,
			height: 420,
			autoRowHeight : false,
			singleSelect : false,
			striped : true,
			url : '${systemctx}/systemmanage/userDuty/user/getUserDutyListJson.json',
			sortName: 'modifytime',
			sortOrder: 'desc',
			remoteSort : true,
			idField : 'dutyid',
			pagination : true,
			rownumbers : true,
			showFooter : true,
			columns : [ [ 
				{field:'ck', checkbox:true},
				{title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.column.dutycode") %>',field : 'dutycode',sortable : true,align : 'left',width:140}, 
				{title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.column.dutyname") %>',field : 'dutyname',sortable : true,align : 'left',width:140}, 
				{title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.userduty.column.dutycheckstatus") %>',field : 'dutycheckstatus',width : 100, sortable : true, align : 'center'}, 
				{field : 'dutyid',hidden:true} 
			] ],
			onLoadSuccess : function(data) {
				var idList = new Array()
				if(ids != '' && ids != undefined){
					idList = ids.split(",");
				}
	            var rowData = data.rows;
	            $.each(rowData, function (index, value) {
	            	$.each(idList, function (idIndex, id) {
		               if (value.dutyid == id) {
		            	   $("#datagrid").datagrid("checkRow", index);
		               }
	            	});
	            });
			}
		});

		$('#butQuery').click(function() {
			$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
	
	});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>